﻿@{
    ViewBag.Title = "Восстановление пароля";
    Layout = "~/Views/Shared/_Layout.cshtml";

    var public_key = System.Configuration.ConfigurationManager.AppSettings["CAPTCHA_PUBLIC_KEY"];

}

<script>
    $(function () {

        var start_view = Backbone.View.extend({
            el: $("#start-page"),

            render: function () {
                $(".block").hide();
                $(this.el).show();
            },

            events: {
                "click .btn[data-action='passwordReset']": "passwordReset",
                "click .btn[data-action='back']": "back"
            },

            passwordReset: function () {
                $.ajax({
                    type: 'POST',
                    url: '/security/PasswordReset/',
                    data: $("form[name='REGISTER']").serialize(),
                    success: function () {
                        window.history.back();
                    },
                    error: function (data) {
                        var error = jQuery.parseJSON(data.responseText);
                        var errorMessage = error.message;

                        $("#alertMessage").text(errorMessage);
                        $("#alert").show();
                    }
                });
            },

            back: function () {
                window.history.back();
            }

        });

        var Controller = Backbone.Router.extend({
            routes: {
                "": "start", // Пустой hash-тэг
                "!/": "start" // Начальная страница
            },

            initialize: function (options) {
            },

            start: function () {
                var view = new start_view();
                view.render();
            }
        });

        var controller = new Controller(); // Создаём контроллер
        Backbone.history.start();  // Запускаем HTML5 History push 

    });
</script>

<header class="jumbotron subhead" id="overview">
    <h1></h1>
    <p class="lead">Восстановление пароля</p>
</header>

<div class="page">

    <div class="block" id="start-page">
        <div class="form-actions">
            <a href="javascript:void(0);" class="btn" data-action="back"><i class="icon-circle-arrow-left"></i> Назад</a>
            <div class="pull-right">
                <a href="javascript:void(0);" class="btn btn-primary" data-action="passwordReset">Выслать новый пароль</a>
            </div>
        </div>    
            
        <div class="alert alert-error hide" id="alert">
            <h4>Ошибка!</h4>
            <span id="alertMessage"></span>
        </div>

        <div>
            <form name="REGISTER" class="form-horizontal" method="post"> 
                <fieldset> 
                    <div class="control-group error"> 
                        <label class="control-label" for="EMAIL">Email</label>
                        <div class="controls">
                            <input type="text" class="input-large" name="EMAIL" value="" />
                        </div> 
                    </div> 

                    <div class="control-group error"> 
                        <label class="control-label" for=""></label>
                        <div class="controls">
                            @ReCaptcha.GetHtml(public_key, theme: "white")
                        </div> 
                    </div>
                </fieldset>
            </form>
        </div>
    </div>
</div>